﻿using System;
using System.Threading;

namespace Crawler.Domain.DataEntities
{
	public class CrawlingSession
	{

		public CrawlingSession()
		{
			EndDateUtc = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
		}
		private int _pagesCrawled=0;
		private int _pagesProcessed=0;
		private int _pagesDownloaded=0;
		public virtual int Id { get; set; }
		public virtual string SessionId { get; set; }
		public virtual TorrentSource Source { get;  set; }
		public virtual DateTime UtcCrawled { get; set; }
		public virtual string FromUrl { get; set; }
		//public virtual string SessionId { get; set; }
		public virtual bool IsCompleted { get; set; }

		public virtual DateTime StartDateUtc { get; set; }

		public virtual DateTime EndDateUtc { get; set; }

		public virtual int PagesCrawled
		{
			get { return _pagesCrawled; }
			set { _pagesCrawled = value; }
		}

		public virtual int PagesProcessed
		{
			get { return _pagesProcessed; }
			set { _pagesProcessed = value; }
		}

		public virtual bool Succeed { get; set; }

		public virtual int PagesDownloaded
		{
			get { return _pagesDownloaded; }
			set { _pagesDownloaded = value; }
		}

		public virtual string Folder { get; set; }
		public virtual bool CrawlCompleted { get; set; }
		public virtual bool PagesProcessedCompleted { get; set; }

		public virtual void IncrementPagesCrawled()
		{
			Interlocked.Increment(ref _pagesCrawled);
		}

		public virtual void IncrementPagesProcessed()
		{
			Interlocked.Increment(ref _pagesProcessed);
		}

		public virtual void IncrementPagesContentDownloaded()
		{
			Interlocked.Increment(ref _pagesDownloaded);
		}
	}


}